package jdbc;

import entity.Student;
import util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class Limit {
    public static void main(String[] args) {
        //一页10条，查询第三页
        //(页号-1)* 页大小
        String sql="select * from s_student order by stuno desc limit 20,10";
        Connection con= DBUtil.getConnection();
        PreparedStatement ps=null;
        ResultSet rs=null;
        List<Student> datas=new ArrayList<>();
        try {
            ps=con.prepareStatement(sql);
            rs=ps.executeQuery();
            while (rs.next()){
                Student st=new Student();
                st.setStuno(rs.getLong("stuno"));
                st.setSname(rs.getString("sname"));
                st.setTelephone(rs.getString("telephone"));
                //...
                datas.add(st);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(rs,ps,con);
        }
        for(Student s:datas)
            System.out.println(s);

    }
}
